﻿using System.Text.RegularExpressions;

namespace newBlog.CenterInc.tool
{
    public class isString
    {
        //字符串一系列判断的操作类
        public bool IsNotEmpty(params string[] strarr)
        {//传递一个可变参数进行判断是否为空
            if (strarr.Length == 0 || strarr == null)
            {
                return true;
            }
            int i = 0;
            int count = strarr.Length;
            for (; i < count; i++)
            {
                if (strarr[i] != null || strarr[i].Length != 0)
                {
                    return true;
                }
            }
            return false;
        }
        public bool IsRange(int min, int max, params string[] strarr)
        {
            int i = 0;
            int count = strarr.Length;
            for (; i < count; i++)
            {
                if (strarr[i].Length < min || strarr[i].Length > max)
                {
                    return true;
                }
            }
            return false;
        }//传递一个可变参数进行判断字符数量是否再范围内
        public bool IsChar(string pattern, params string[] strarr)
        {
            if (strarr == null || strarr.Length == 0)
            {
                return true;
            }
            int i = 0;
            int count = strarr.Length;
            for (; i < count; i++)
            {
                if (Regex.IsMatch(strarr[i], pattern))
                {
                    return true;
                }
            }
            return false;
        }//判断正则表达式是否存在指定内容
        public bool isEmpty(params string[] strarr)
        {
            if (strarr == null || strarr.Length == 0)
            {
                return true;
            }
            int i = 0;
            int count = strarr.Length;
            for (; i < count; i++)
            {
                if (strarr[i] == null || strarr[i].Length == 0)
                {
                    return true;
                }
            }
            return false;
        }//判断是否有空字符
        public string filterHtml(string txt)
        {
            txt.Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("&", "&amp;");
            return txt;
        }
        public string getfilterHtml(string txt)
        {
            txt.Replace("\"", "\\\"").Replace("\'", "\\\'").Replace("<", "\\\\<").Replace(">", "\\\\>");
            return txt;
        }//过滤字符串并传递进数据库
    }
}